#include "../pch.h"



namespace BFX
{

// Initializes a new instance of the decoder class.
REFDecoder::REFDecoder(const REFEncoding* pEncoding)
{
	BFX_ASSERT(pEncoding != NULL);
	m_pEncoding = pEncoding;
	m_bFlushRequired = false;
	Reset();
}
// Destorys the current instance of decoder class.
REFDecoder::~REFDecoder()
{
}

void REFDecoder::Reset()
{
	if (m_pFallbackBuffer != NULL)
		m_pFallbackBuffer->Reset();
}

int REFDecoder::GetCharCount(const BYTE* pBytes, int nCount, bool bFlush)
{
	// remember the flush
	m_bFlushRequired = bFlush;

	// By default just call the encoding version, no flush by default
	return m_pEncoding->GetCharCount(pBytes, nCount, this);
}

int REFDecoder::GetChars(const BYTE* pBytes, int nByteCount, OUT UCHAR* pChars, int nCharCount, bool bFlush)
{
	// remember the flush
	m_bFlushRequired = bFlush;

	// By default just call the encoding's version
	return m_pEncoding->GetChars(pBytes, nByteCount, pChars, nCharCount, this);
}

// Gets a fallback buffer object for the current decoder object, or create a instance if not exists.
REFDecoderFallbackBuffer* REFDecoder::GetFallbackBuffer()
{
	if (m_pFallbackBuffer == NULL)
	{
		// creates a new fallback buffer if necessary.
		m_pFallbackBuffer = m_pEncoding->GetDecoderFallback()->CreateFallbackBuffer();
	}
	return m_pFallbackBuffer;
}

}	//	namespace BFX
